<?

/* DefaultModel model class.
 * This class contains data model implementation code.
 *
 */ 
/* @author Udo Schroeter <udo.schroeter@gmail.com>
 * @license dual license: LGPL / commercial use license
 */ 

class MapModel extends AGModel
{
  // model data
  var $data;

  function __construct($modelName) 
  {
    parent::__construct($modelName);
    // your constructor code goes here
    
  }
  
  function loadMapState($charId, $zoneId)
  {
    $this->charId = $charId;
    $this->zoneId = $zoneId;
    $this->mapstateDS = DB_GetDatasetMatch('mapstates', array(
      'ms_character' => $charId,
      'ms_zone' => $zoneId, 
      ));
    $this->mstats = TextToStringlist($this->mapstateDS['ms_state']);
  }
  
  function saveMapState()
  {
    $this->mapstateDS['ms_state'] = StringlistToText($this->mstats);
    $this->mapstateDS['ms_character'] = $this->charId;
    $this->mapstateDS['ms_zone'] = $this->zoneId;
    DB_UpdateDataset('mapstates', $this->mapstateDS);
  }
  
  function updateExploredMapState($expString)
  {
    $el = strlen($expString);
    $y = 0;
    $x = -1;
    for($i = 0; $i < $el; $i++)
    {
      $c = substr($expString, $i, 1);
      $x++;
      switch($c)
      {
        case(':'): {
          $x = -1;
          $y++;
          break;
        }
        case(1): {
          $this->mstats['explored.'.$x.'.'.$y] = 1;
          break;
        }                
      }
    }
  }

}


?>
